package com.hsmw.api.controller.pub;


import com.alibaba.fastjson.JSONObject;
import com.hsmw.api.service.HsmwSmsService;
import com.hsmw.api.service.HsmwUserService;
import com.hsmw.common.base.BaseController;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.constant.CommonConstants;
import com.hsmw.domain.HsmwSms;
import com.hsmw.domain.HsmwUser;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.*;;import java.util.HashMap;

@Api(tags = "PUB-通信接口", produces = "application/json")
@RestController
@RequestMapping("/api/pub/ocr")
public class OCRController extends BaseController<HsmwUserService, HsmwUser> {
	private static org.slf4j.Logger Logger = LoggerFactory.getLogger(OCRController.class);


	@Autowired
	private HsmwSmsService hsmwSmsService;

	@ApiOperation(value = "身份证识别", notes = "参数  手机号：username;")
	@PostMapping(value = "/getIDInfoByOCR")
	public   DataResponse sendSmsCode(@RequestBody JSONObject jsonObject,HsmwUser hsmwUser) {
		try{

			Credential cred = new Credential(CommonConstants.SECRET_ID, CommonConstants.SECRET_KEY);
			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setEndpoint("faceid.tencentcloudapi.com");
			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setHttpProfile(httpProfile);

			FaceidClient client = new FaceidClient(cred, "", clientProfile);

			IdCardVerificationRequest req = new IdCardVerificationRequest();
			req.setIdCard("372901198902043454");
			req.setName("王栋");

			IdCardVerificationResponse resp = client.IdCardVerification(req);

			System.out.println(IdCardVerificationResponse.toJsonString(resp));



			return new DataResponse();
		} catch (TencentCloudSDKException e) {
			System.out.println(e.toString());
			return new DataResponse(CommonConstants.ResponseStatus.FAIL,"OCR识别失败，原因是"+e.getMessage());
		}

	}


	public static void main(String [] args) {
		try{

			Credential cred = new Credential("AKIDAvnTRAW5C4mT8gDMUTn0ylQDl32pup47", "Tw9z7zdzBZllhNnzmgRzKyPbXEwPfeU5");

			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setEndpoint("faceid.tencentcloudapi.com");

			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setHttpProfile(httpProfile);

			FaceidClient client = new FaceidClient(cred, "", clientProfile);

			IdCardVerificationRequest req = new IdCardVerificationRequest();
			req.setIdCard("372901198902043454");
			req.setName("王栋");

			IdCardVerificationResponse resp = client.IdCardVerification(req);

			System.out.println(IdCardVerificationResponse.toJsonString(resp));
		} catch (TencentCloudSDKException e) {
			System.out.println(e.toString());
		}

	}

}
